package com.hinnotek.amoeba.ui.fragment

import android.view.View
import android.widget.Switch
import cn.jpush.android.api.JPushInterface
import com.flyco.dialog.listener.OnBtnClickL
import com.flyco.dialog.widget.NormalDialog
import com.hinnotek.amoeba.R
import com.hinnotek.amoeba.databinding.FragmentHomeMineBinding
import com.hinnotek.amoeba.ui.activity.old.AboutUsActivity
import com.hinnotek.amoeba.ui.activity.old.ChangeLoginPasswordActivity
import com.hinnotek.amoeba.ui.activity.old.LoginActivity
import com.hinnotek.amoeba.utilities.IntentUtils
import com.lee.common.utils.SharedPreUtils
import com.lee.common.base.BaseFragment
import timber.log.Timber

/**
 * "我的"Fragment标签页
 */
class FragmentHomeMine : BaseFragment<FragmentHomeMineBinding>(), View.OnClickListener {

    private var sw_notification: Switch? = null
    private var normalDialog: NormalDialog? = null

    override fun initData() {

        Timber.e("jpush_id:${JPushInterface.getRegistrationID(mContext)}")

        mBinding.tvUserNameStr.text = SharedPreUtils.getString("userName")
        mBinding.tvUserNameStr.setOnClickListener(this)
        mBinding.superButtonLogout.setOnClickListener(this)
        var versionName = ""
        try {
            val pkName = mContext.packageName
            versionName = mContext.packageManager.getPackageInfo(pkName, 0).versionName
            //int versionCode = this.getPackageManager().getPackageInfo(pkName, 0).versionCode;
        } catch (e: Exception) {
        }

        mBinding.tvVersionNameStr1.text = versionName


        mBinding.rlGoPassword.setOnClickListener(this)
        mBinding.rlGoAboutUsBtn.setOnClickListener(this)
        /*if (JPushInterface.isPushStopped(context)) {
            sw_notification?.isChecked = false
        } else {
            sw_notification?.isChecked = true
        }*/
        sw_notification?.setOnCheckedChangeListener { buttonView, isChecked ->
            if (isChecked) {
                //JPushInterface.resumePush(context)
            } else {
                //JPushInterface.stopPush(context)
            }
        }
    }

    override fun getLayoutId(): Int {
         return R.layout.fragment_home_mine
    }



    //退出登录
    private fun userLogout() {
        normalDialog = NormalDialog(context)
        normalDialog!!.content("确定退出该账户？")
            .btnNum(2)
            .style(NormalDialog.STYLE_TWO)
            .titleTextSize(23f)
            .show()
        normalDialog?.setOnBtnClickL(object : OnBtnClickL {
            override fun onBtnClick() {
                normalDialog?.dismiss()
            }
        }, object : OnBtnClickL {
            override fun onBtnClick() {
                normalDialog?.dismiss()
                //JPushInterface.deleteAlias(context, 0)
                SharedPreUtils.setBoolean("isLogin",false)
                IntentUtils.startActivity(context, LoginActivity::class.java)
                activity?.finish()
            }
        })
    }

    override fun onClick(view: View) {
        when (view.id) {
            R.id.superButton_logout -> userLogout()
            R.id.tv_userName_str -> {
            }
            R.id.rl_go_password -> IntentUtils.startActivity(context,ChangeLoginPasswordActivity::class.java)
            R.id.rl_go_about_us_btn -> IntentUtils.startActivity(context, AboutUsActivity::class.java)
        }
    }


}